<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>使用函数</title>
</head>
<body>
	<h1>使用函数来处理</h1><hr>
	<script type="text/javascript">
	<!--	
		function validateField(field) {
			if(field.value == "") {
				alert("用户名必须输入");
				field.focus();
				return false;
			} else {
				Name = field.value;
				alert(Name + ",欢迎光临");
			}
		return true;
		}
	//-->	
	</script>
	<form action="#" method="get" onsubmit="return validateField(this.username);">
		<input type="text" name="username" id="username"></input>
		<input type="submit" value="登入">
	</form>
</body>
</html>